<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../../resource/css/bootstrap.min.css"/>
		<link rel="stylesheet" type="text/css" href="../../../resource/css/jedate.css"/>
		<link rel="stylesheet" type="text/css" href="../../../resource/fonts/iconfont.css"/>
		<link rel="stylesheet" type="text/css" href="../../../resource/css/common.css"/>
		<style>
		</style>
	</head>
	<body>
		<div class="container-fluid">
			<div class="row mheader">
				<div class="col-xs-2 text-left"><a href="javascript:;" onclick="javascript:history.back(-1);"><span class="iconfont icon-fanhui"></span></a></div>
				<div class="col-xs-8"><h2>申请审批详情</h2></div>
			</div>
			<div class="row">
				<dl class="erp-list erp-details">
					<dd>
						<div id="dd1" class="erp-txt visa-txt">
						</div>
					</dd>
				</dl>
				<dl id="d2" class="erp-order material-order">
					<dt>材料单</dt>

					<!--<dd>-->
						<!--<p><span>材料名称:</span>水泥</p>-->
						<!--<div class="order-li clearfix">-->
							<!--<div class="col-xs-6"><span>规格:</span>100x200</div>-->
							<!--<div class="col-xs-6 text-right"><span>数量:</span><strong>20</strong><span>个</span></div>-->
							<!--<div class="col-xs-6"><span>单位:</span>t</div>-->
							<!--<div class="col-xs-6 text-right"><span>备注:</span><strong>正常</strong><span></span></div>-->
						<!--</div>-->
						<!---->
					<!--</dd>-->
					
				</dl>
		

				<div style="margin-bottom: 80px;"></div>
				<div id="sh" class="order-send hidden"><button onclick="sub()" class="btn btn-warning">审批</button></div>

			</div>
		</div>
	</body>
</html>
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="../../../resource/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../resource/js/style.js"></script>
<script src="../../../resource/js/base64.js"></script>
<script type="text/javascript">

    var danhao;
	//点击改变申请单高度
	$(document).ready(function(){
		$(".more").click(function(){
		$(this).siblings(".order-li").toggleClass("orderHeight");
  	});


//        var datajson = sessionStorage.getItem('lhr_clsqsp');
//		  var json = JSON.parse(datajson);
//		  danhao = json.feed_Code;


		var feed_Code=window.location.href.split("?")[1];
        danhao=feed_Code;
        var sendata = {'type':'c'};
        sendata['remark'] = feed_Code;
        sendata['p'] = getP();
        ajaxs(
            "api/matperson/gcMatFeedSel.do", "post", sendata,
            function (data) {
                dropDown = data.fullDown;
                var data = data.data;
                console.log(data)
                $('#dd1').append('<p><span >供货单号:</span>'+data[0].feed_Code+'</p>'+
                '<p class="clearfix"><span class="sp">项目名称:</span><span class="divCon">'+data[0].eppName+'('+data[0].eppStaEnd+')'+'</span></p>'+
				'<p class="clearfix"><span class="sp">施工单位:</span><span class="divCon">'+data[0].compName1+'</span></p>'+
                '<p><span>供货时间:</span>'+data[0].supply_Time+'</p>'+
                '<p><span>收货地址:</span>'+data[0].eppStaEnd+'</p>'
				);
                if(data[0].validate == '-1'){
                    $('#sh').removeClass('hidden');
                }
                var htmls= '';
                for (var i=0; i < data.length;i++){
                    d = data[i];
                    var dw = '';
                    console.log(d);
                    var model = '<dd class="myfrom-sub">' +
                        '<p><span>材料名称:</span>'+d.mat_Name+'</p>' +
                        '<div class="order-li clearfix">' +
                        '<div class="col-xs-7 clearfix"><span>材料规格:</span>'+d.mat_Spec+'</div>' +
                        '<div class="col-xs-5 clearfix"><span>申请人:</span>'+d.feed_sqr+'</div>' +
                        '<div class="col-xs-7 clearfix"><span>申请数量:</span><strong class="feed_Num">'+d.feed_Num+'</strong>'+d.mat_Bit+'</div>' +
                        '<div class="col-xs-5 clearfix"><span>审核量:</span><input type="text" class="fv_num mD-num" value="{{fv_num}}"/></div>' +
                        '<div class="col-xs-12 clearfix"><span>材料供应商:</span><select class="sup_code" value="'+d.sup_Code+'">{{dorpDown}}</select></div>' +
                        '<div class="col-xs-12 clearfix"><span>审核状态:</span><select class="validate" value="'+d.validate+'"><option value="0">审核通过</option><option value="1">审核不通过</option></select></div>' +
                        '<div class="col-xs-12 clearfix"><span>审核意见:</span><input class="valopition mD-num" type="text" value="'+isun(d.valOpition)+'" /></div>' +
                        '<span class="hidden mat_Id">'+d.mat_Id+'</span>'+
                        '<span class="hidden id">'+d.id+'</span>'+
                        '</div>' +
                        '</dd>';

                    switch (d.mat_Type){
                        case 1:
                            for (var j=0;j<dropDown.fullDown1.length;j++){
                                dw += '<option value="'+dropDown.fullDown1[j].compid+'">'+dropDown.fullDown1[j].compName+'</option>'
                            }
                            break;
                        case 2:
                            for (var j=0;j<dropDown.fullDown2.length;j++){
                                dw += '<option value="'+dropDown.fullDown2[j].compid+'">'+dropDown.fullDown2[j].compName+'</option>'
                            }
                            break;
                        case 3:
                            for (var j=0;j<dropDown.fullDown3.length;j++){
                                dw += '<option value="'+dropDown.fullDown3[j].compid+'">'+dropDown.fullDown3[j].compName+'</option>'
                            }
                            break;
                        case 4:
                            for (var i=0;i<dropDown.fullDown4.length;i++){
                                dw += '<option value="'+dropDown.fullDown4[i].compid+'">'+dropDown.fullDown4[i].compName+'</option>'
                            }
                            break;
                    }

                    model = model
                        .replace('{{dorpDown}}',dw)
                        .replace('{{fv_num}}',(d.fv_Num ==undefined)?d.feed_Num:d.fv_Num);
                    htmls += model;

                }
                $('#d2').html($('#d2').html()+htmls);
				$('.sup_code').each(function (e) {
					this.value=$(this).attr('value');
                });
                $('.validate').each(function (e) {
                    this.value=$(this).attr('value');
                });

				if(d.validate==-1){
                    $('.sup_code').removeAttr('disabled');
                    $('.validate').removeAttr('disabled');
                }else{
				    $('.sup_code').attr('disabled','disabled');
                    $('.validate').attr('disabled','disabled');
                    $('input').attr('disabled','disabled');

                }
            }
        )
        

	});

    function isun(data) {
        if (data == undefined){
            return '';
        }
        return data;
    }
    function isunnum(data) {
        if (data == undefined){
            return 0;
        }
        return data;
    }
	function sub() {
        var htmls = $('.myfrom-sub');
        var datas = [];
		var zhuangtais=true;

        $('.sup_code').each(function (k,v) {
			if(!$(v).val()){
                window.tool.alert('请检查供货商是否选中');
                zhuangtais=false;
			    return false;
			}
        })



		if(zhuangtais){
            for (var i=0;i<htmls.length;i++){
                html = htmls[i];
                var json ={
                    "createtime": null,
                    "valtime":null,
                    "createuser": "",
                    "valopition": html.getElementsByClassName('valopition')[0].value,
                    "fv_num": html.getElementsByClassName('fv_num')[0].value,
                    "feed_code": "",
                    "feed_num": $('.feed_Num').html(),
                    "sup_code": html.getElementsByClassName('sup_code')[0].value,
                    "mat_id": html.getElementsByClassName('mat_Id')[0].innerHTML,
                    "valperson": "",
                    "id": html.getElementsByClassName('id')[0].innerHTML,
                    "state": 0,
                    "updatetime": null,
                    "remarks": "",
                    "validate":html.getElementsByClassName('validate')[0].value
                }
                datas.push(json);
            }
            console.log(datas)

            var base = new Base64();
            $.ajax({
                url:urls+'api/matperson/matFeedVali.do',
                data:JSON.stringify(datas),
                contentType: "application/json; charset=utf-8",
                headers: {
                    'p': base.encode(getP()),
                    'danhao': danhao
                },
                dataType: 'json',
                type:'post',
                success:function(data){
                    console.log(data)
                    window.tool.alert(data[0].msg);
                    window.location.href="./erp-list.html";
                }
            })
		}


    }
    $(function () {
        //判断数量输入框是否为空
        $('#d2').on('focus','.fv_num',function () {
            console.log($(this))
            $(this).keyup(function () {
                console.log($(this).val()<=0)
                if($(this).val()<=0){
                    $('.btn-warning').hide();
                    window.tool.alert('数量不能小于0,请修改');
                    return;
                }else{
                    $('.btn-warning').show();
                }
            })
        })


    })


</script>











